package com.sq.partner.manager.dao.impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.sq.partner.manager.dao.FacadePaymentDao;
import com.sq.partner.manager.mybatis.model.FacadeAppForm;
import com.sq.partner.manager.mybatis.model.FacadePayment;
import com.sq.partner.manager.mybatis.model.FacadeTransLog;

/**
 * 支付信息DAO实现类
 * 
 * @author zhouxiuxiu
 *
 */
@Repository
public class FacadePaymentDaoImpl extends BaseDaoImpl implements
        FacadePaymentDao {

    /**
     * 根据投保单号查询交易记录表中交易流水号末尾最大4位数
     */
    @Override
    public String findFacadeTransLogByTransNo(String appno) throws Exception {
        return (String) query("queryFacadeTransLogByTransNo", appno);
    }

    /**
     * 缴费发送前插入交易记录表信息
     */
    @Override
    public void insertFacadeTransLog(FacadeTransLog translog) throws Exception {
        this.add("insertFacadeTransLog", translog);
    }

    /**
     * 查询投保单表状态为支付成功或出单失败的支付及保单信息
     * 
     * @param map
     * @return
     * @throws Exception
     */
    @SuppressWarnings("unchecked")
    @Override
    public Map<String, Object> queryConfirmAgainMessage(Map<String, Object> map)
            throws Exception {
        return (Map<String, Object>) query("queryConfirmAgainMessage", map);
    }

    /**
     * 缴费接受后更新交易记录表信息
     * 
     * @param translog
     * @throws Exception
     */
    @Override
    public void updateFacadeTransLog(FacadeTransLog translog) throws Exception {
        this.update("updateFacadeTransLogNotNull", translog);
    }

    /**
     * 更新投保单表信息
     * 
     * @param map
     * @throws Exception
     */
    @Override
    public void updateFacadeAppFormByAppno(Map<String, Object> map)
            throws Exception {
        this.update("updateFacadeAppFormByAppno", map);
    }

    /**
     * 确认该保单号是否为最后一个缴费确认
     * 
     * @param map
     * @return
     * @throws Exception
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<String> queryConfirmToLast(Map<String, Object> map)
            throws Exception {
        return (List<String>) this.queryList("queryConfirmToLast", map);
    }

    /**
     * 查询暂存单号最后一次支付记录
     * 
     * @param payid
     * @return
     * @throws Exception
     */
    @Override
    public FacadePayment queryFacadePaymentByPayidTheLatestInsertTime(
            String payid) throws Exception {
        return (FacadePayment) this.query(
                "queryFacadePaymentByPayidTheLatestInsertTime", payid);
    }

    /**
     * 通过暂存单号修改出单系统暂存单表
     */
    @Override
    public void updateFacadeTempPolicy(Map<String, Object> map)
            throws Exception {
        this.update("updateFacadeTempPolicyByStagNo", map);
    }
    /**
     * 根据暂存单号生成支付流水号
     * @param stagNo
     * @return
     * @throws Exception
     */
    @Override
    public String findFacadePaymentBystagNo(String stagNo) throws Exception {
        return (String) this.query("queryFacadePaymentBystagNo", stagNo);
    }
    
    /**
     * 插入支付记录
     * @param payment
     * @throws Exception
     */
    @Override
    public void saveFacadePayment(FacadePayment payment) throws Exception {
        this.add("insertFacadePayment", payment);
    }
    
    /**
     * 更新支付记录
     * @param payment
     * @throws Exception
     */
    @Override
    public void updateFacadePayment(FacadePayment payment) throws Exception {
        this.update("updateFacadePaymentNotNull", payment);
    }
    
    /**
     * 通过暂存单号修改投保单表
     */
    @Override
    public void updateFacadeAppForm(Map<String, Object> map) throws Exception {
        this.update("updateFacadeAppFormByPayId", map);
    }
    
    /**
     * 暂存单号查询保单信息
     * 
     * @param payId
     * @return
     * @throws Exception
     */
    @SuppressWarnings("unchecked")
    @Override
    public List<FacadeAppForm> findFacadeAppFormByAppno(String payId)
            throws Exception {
        return (List<FacadeAppForm>) queryList("queryFacadeAppFormByAppno", payId);
    }
    
    @SuppressWarnings("unchecked")
    @Override
    public List<FacadePayment> queryFacadePaymentByPayid(String payid)
            throws Exception {
        return (List<FacadePayment>) queryList("queryFacadePaymentByPayid",
                payid);
    }

}
